<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thinhhung
 * Date: 6/5/12
 * Time: 9:08 AM
 * To change this template use File | Settings | File Templates.
 */
//print_r($doanhnghiep);
///echo $doanhnghiep['0']['doanhnghiep']['TENCT'];

//print_r($loaikh);
//echo $hoadon['0']['HoaDonBan']['NGAYBAN'];
//echo $ngayban;
//echo $loaikh['0']['a']['DOITUONGKH_ID'];
//print_r($khachhang);
//echo $giamgia['0']['giamgia']['MUCGIAMGIA'];

App::uses('CakeNumber', 'Utility');
?>
<div id="view">
    <div class="thongtin">
        <div class="head_title"><h1 ALIGN="CENTER" style="font-size: xx-large;">HÓA ĐƠN BÁN HÀNG</h1></div>

        <div id="ngày">
            <p align="center">Số : <?php echo $hoadonban['HoaDonBan']['id']; ?>
                | Ngày : <?php echo date('d-m-Y', strtotime($hoadonban['HoaDonBan']['NGAYBAN'])); ?> </p>
            <br>
        </div>


        <div id="bennhap" style="float: left; margin-left: 3em">
            <p>Bên bán : <?php echo $doanhnghiep['0']['doanhnghiep']['TENCT']; ?> </p>

            <p>Địa chỉ : <?php echo $doanhnghiep['0']['doanhnghiep']['DIACHICT']; ?> </p>

            <p>Mã số thuế : <?php echo $doanhnghiep['0']['doanhnghiep']['MSTCT']; ?> </p>
            <br>
        </div>
        <div id="benban" style="float: right; margin-right: 4em">
            <p>Bên mua : <?php echo $khachhang['0']['KhachHang']['TENKH']; ?></p>

            <p>Địa chỉ : <?php echo $khachhang['0']['KhachHang']['DIACHIKH']; ?></p>


        </div>
    </div>
    <table>
        <tr>
            <th>TÊN HÀNG HÓA</th>
            <th>ĐƠN VỊ TÍNH</th>
            <th>SỐ LƯỢNG</th>
            <th>ĐƠN GIÁ (VNĐ)</th>
            <th>THÀNH TIỀN</th>
        </tr>

        <?php foreach ($chitietbans as $chitietban) : ?>
        <tr>
            <td><?php echo $chitietban['b']['TENSP']; ?></td>
            <td><?php echo $chitietban['b']['DONVITINH']; ?></td>
            <td><?php echo $chitietban['a']['SLBAN']; ?></td>
            <td><?php
                echo CakeNumber::currency($chitietban['a']['DONGIABAN'], '', array('thousands' => '.', 'decimals' => ',',)); ?></td>
            <td><?php
                echo CakeNumber::currency($chitietban['a']['SLBAN'] * $chitietban['a']['DONGIABAN'], '', array('thousands' => '.', 'decimals' => ',',)); ?></td>
        </tr>
        <?php endforeach; ?>
    </table>
    <br>

    <div class="thongtin">
        <div id='tongtien' style="float: left; margin-left: 3em">

            <?php
            echo "<p>Tổng tiền trước thuế : " .
                CakeNumber::currency($tongtien, '', array('thousands' => '.', 'decimals' => ',',)) . " VNĐ  | Giảm giá : " . $giamgia . " VNĐ</p>";

            echo "<p>Thuế : " . $hoadonban['HoaDonBan']['THUEBAN'] . "%" . " | Tiền thuế : "
                . CakeNumber::currency($tienthue, '', array('thousands' => '.', 'decimals' => ',',)) . " VNĐ</p>";
            echo "<p>Tổng tiền sau thuế : " . CakeNumber::currency($tiensauthue, '', array('thousands' => '.', 'decimals' => ',',)) . " VNĐ</p><br>";
            ?>
        </div>

        <div id='tientra' style="float: right; margin-right: 3em">
            <?php
            echo '<p>Đã trả : ' . CakeNumber::currency($datra,'', array('thousands'=> '.',  'decimals' => ',',)) . ' VNĐ </p>';
            $conthieu = $tiensauthue - $datra;
            echo '<p>Còn thiếu : ' . CakeNumber::currency($conthieu,'', array('thousands'=> '.',  'decimals' => ',',)) . ' VNĐ</p>';
            ?>
        </div>
    </div>
    <div style="clear:both;"></div>
    <div id="ct" style="float: right; margin-right: 10em">
        <h3><b>BÊN MUA</b></h3>
        <h6>(Kí tên)</h6>
    </div>

    <div id="nv" style="float: left; margin-left: 10em">
        <h3><b>BÊN BÁN</b></h3>
        <h6>(Kí tên)</h6>
        <br><br><br>

        <h4><?php echo $tennv['0']['NhanVien']['TENNV']; ?></h4>
    </div>

    <div id='btn' style="align: center;">
        <?php
        if ($datra == 0) {
            echo $this->Form->create('HoaDonBan', array('action' => 'pay', 'style' => 'text-align: center;'));
            echo $this->Form->input('id', array('readonly' => 'readonly', 'style' => 'width:200px', 'value' => $hoadonban['HoaDonBan']['id']));
            echo $this->Form->input('TIENDATRA', array('label' => 'Thanh toán (VNĐ) :', 'style' => 'width:200px'));
            echo $this->Form->submit('Lưu');
            echo $this->Form->end();
        }
        ?>
    </div>
</div>